﻿using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Networking;

public class CameraSyncNet : NetworkBehaviour
{
    public Transform camera;
    public float lerpSpeed = 6;
    [SyncVar] float rotationx;
    
    void FixedUpdate()
    {
        if (isLocalPlayer)
        {
            CmdSend2Server(camera.transform.localRotation.eulerAngles.x);
        }
        else
        {
            LerpPosition();
        }
    }
    
    [Command]
    void CmdSend2Server(float x)
    {
        rotationx = x;
    }

    void LerpPosition()
    {
        camera.transform.localRotation = Quaternion.Slerp(camera.transform.localRotation, Quaternion.Euler(new Vector3(rotationx, 0, 0)), lerpSpeed * Time.fixedDeltaTime);
    }
}
